<template>
	<el-container>
		<el-container>
			<el-header>
						<div class="left-panel">
						</div>
						<div class="right-panel">
							<el-input style="width: 150px;" v-model="search.member_id" placeholder="会员ID" clearable></el-input>
							<el-input style="width: 150px;" v-model="search.idnumber" placeholder="身份证号码或统一信用代码" clearable></el-input>
							<el-input style="width: 150px;" v-model="search.realname" placeholder="真实名称或法人姓名" clearable></el-input>
							<el-select style="width: 100px;" v-model="search.status" clearable
								placeholder="状态" filterable>
								<el-option v-for="(item, key) in statuss" :key="key" :label="item" :value="key" />
							</el-select>
							<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
						</div>
					</el-header>
					<el-main class="nopadding">
						<scTable ref="table" :apiObj="list.apiObj" row-key="id" stripe>
							<el-table-column label="ID" prop="id" width="50"></el-table-column>
							<el-table-column label="类型" prop="type_text" width="100">
							</el-table-column>
							<el-table-column label="会员ID" prop="member_id" width="100">
							</el-table-column>
							<el-table-column label="实名信息" prop="realname" width="300">
								<template #default="scope">
									<p v-if="scope.row.type == '1'">真实姓名：{{scope.row.realname}}</p>
									<p v-if="scope.row.type == '1'">身份证号码：{{scope.row.idnumber}}</p>
									<p v-if="scope.row.type == '2'">法人姓名：{{scope.row.realname}}</p>
									<p v-if="scope.row.type == '2'">统一信用代码：{{scope.row.idnumber}}</p>
									<p v-if="scope.row.type == '2'">法人姓名：{{scope.row.legal_person_name}}</p>
									<p v-if="scope.row.type == '2'">法人电话：{{scope.row.legal_person_phone}}</p>
									<p v-if="scope.row.type == '2'">联系人名称：{{scope.row.contact_name}}</p>
									<p v-if="scope.row.type == '2'">联系人电话：{{scope.row.contact_phone}}</p>
								</template>
							</el-table-column>
							<el-table-column label="身份证照片" prop="cover" width="210">
												<template #default="scope">
													<el-image :preview-src-list="[IMG_URL+scope.row.id_front]"
							:initial-index="0" style="max-height: 100px;margin-right: 10px;" fit="contain" :src="IMG_URL+scope.row.id_front" mode=""></el-image>
																		<el-image :preview-src-list="[IMG_URL+scope.row.id_reverse]"
												:initial-index="0" style="max-height: 100px;" fit="contain" :src="IMG_URL+scope.row.id_reverse" mode=""></el-image>
																	</template>
											</el-table-column>
							<el-table-column label="状态" prop="status_text" width="80">
								<template #default="scope">
									<p >{{scope.row.status_text}}</p>
								</template>
							</el-table-column>
							<el-table-column label="创建时间" prop="create_time" width="170"></el-table-column>
							<el-table-column label="操作" fixed="right" align="right" width="100">
								<template #default="scope">
									<el-button type="primary" plain size="small" @click="statusSave(scope.row)">审核</el-button>
								</template>
							</el-table-column>
						</scTable>
					</el-main>
		</el-container>

	</el-container>

	<realNameSave v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></realNameSave>


</template>

<script>
import configIndex from "@/config"
import realNameSave from './realNameSave.vue'
	export default {
		name: 'realNameList',
		components: {
			realNameSave
		},
		data() {
			return {
				dialog:{
					save: false,
				},
				search: {
					status: '',
					member_id: '',
					idnumber: '',
					realname: '',
				},
				list: {
					apiObj: this.$API.system.user.memberRealNameGetList
				},
				statuss: {'0': '未审核', '1': '审核成功', '2': '审核失败驳回'},
				IMG_URL: configIndex.IMG_URL
			}
		},
		mounted() {

		},
		methods: {
			//搜索
			upsearch() {
				// console.log(112, this.search)
				let search = JSON.parse(JSON.stringify(this.search))
				this.$refs.table.upData({
					...search
				})
			},
			//审核
			statusSave(row){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.saveDialog.open('edit').setData(row)
				})
			},

			//本地更新数据
			handleSaveSuccess(data, mode){
				//为了减少网络请求，直接变更表格内存数据
				this.dialog.save=false
				if(mode=='add'){
					this.$refs.table.unshiftRow(data)
				}else if(mode=='edit'){
					this.$refs.table.updateKey(data)
				}

				//当然也可以暴力的直接刷新表格
				// this.$refs.table.refresh()
			},
			open(url) {
				window.open(url, '_blank')
			}
		}
	}
</script>

<style>
</style>
